home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / VideoToolboxSources / VideoToolbox.h < prev    next >
Text File  |  1996-06-07  |  49KB  |  1,372 lines

  1. /*
  2. VideoToolbox.h
  3. This file contains the necessary prototypes for use of all the VideoToolbox
  4. files except Luminance.c, which has its own header file, Luminance.h, and
  5. GDInfo.c and GDTestClut.c, which use GDInfo.h.
  6.  
  7. Precompilation of this header, producing either VideoToolbox????.pre or
  8. VideoToolboxMATLAB????.pre, will reduce your compilation time tenfold. See
  9. VideoToolbox.pch, or VideoToolbox.c, or VideoToolboxMATLAB.c for instructions.
  10.  
  11. My convention is to assign different names to the precompiled header depending
  12. on the compile-time options: use of ppc/68k, 68881, and size of int.
  13.  
  14. The precompilation depends on the sizeof(double) and sizeof(int)
  15. because most functions use or return such values and the external interface must
  16. allow the appropriate amount of space. THINK C supports a 12-byte "universal"
  17. format double that works well both with the 68881 fpu (which uses the top two
  18. bytes and the bottom 8 bytes) and with SANE (which uses the bottom 10 bytes).
  19. Thus in THINK C it is easy to mix modules compiled with (e.g. your code) and
  20. without (e.g. the ANSI library) the 68881 option. Unfortunately that excellent
  21. feature is unique to THINK C. In MPW and CodeWarrior C you must use 10-byte
  22. doubles when you use SANE (i.e. don't use the 68881 fpu), so when you use these
  23. compilers you'll need separate pre-compiled headers, with and without the 68881
  24. option, if you want to compile for each environment: to use the 68881 fpu, or
  25. run on machines that lack it.
  26.  
  27. Metrowerks CodeWarrior project names end in "µ", and indicate which cpu they
  28. support by "68k" or "ppc". THINK C projects support only the 68k and have names
  29. ending in "π".
  30.  
  31. My naming convention for pre-compiled headers indicates the size of int, "2i" or
  32. "4i", and, if the 68881 is required, "881". Metrowerks pre-compiled headers
  33. indicate which cpu they support by "68k" or "ppc"; THINK C supports only the
  34. 68k. The THINK C pre-compiled header that I use is "VideoToolbox.pre", which
  35. uses 2-byte ints and "universal" 12-byte doubles that work with or without the
  36. 68881. (The THINK C ANSI library requires 2-byte ints.) The Metrowerks
  37. CodeWarrior C pre-compiled headers that I use are called,
  38. "VideoToolbox.68k.4i.pre", "VideoToolbox.68k.4i.881.pre", and
  39. "VideoToolbox.ppc.pre".
  40.  
  41. As of June 14, 1995, the VideoToolbox #includes <assert.h>, or, if MATLAB
  42. is true, defines a MATLAB-compatible version of assert(). If your source file
  43. #includes <assert.h> then it will be included again, which will obviate the work
  44. done here, including the MATLAB compatibility. For that reason you should NOT
  45. #include <assert.h> in your source files.
  46.  
  47. MAC_C:
  48.  
  49. Defining the symbol MAC_C as 0 before this file is compiled will leave only the 
  50. stuff that is written in pure Standard C, which will work on any computer.
  51.  
  52. The Apple Macintosh header files use some extensions to C that are not part of
  53. Standard C, e.g. "pascal", "short double", enums larger than ints, and function
  54. prototypes that specify absolute addresses. These keywords and constructions
  55. cannot be compiled in Standard C. The macro MAC_C is defined as true, below,
  56. only on Macintosh C compilers that incorporate these extensions, and is false
  57. otherwise. The MAC_C symbol is used to prevent inclusion of all the
  58. Macintosh-dependent header files and prototypes when the compiler doesn't
  59. support them. However, lacking any general test for these extensions, a test
  60. must be added, below, for each new compiler. At present we test for Symantec C
  61. THINK C, Apple MPW C, and Metrowerks CodeWarrior C.
  62.  
  63. MATLAB:
  64.  
  65. The VideoToolbox sources can be linked to create a stand-alone C application, or
  66. a MATLAB external code resource (a "MEX" file), to be invoked by typing the
  67. function name from within MATLAB. In that case we call the THINK C project a
  68. "MATLAB project". A MATLAB project must #define the symbol MATLAB as true for
  69. every C file, must #include the VideoToolbox.h header at the beginning of every
  70. C file, and must #include MATLABMain.h in the main C file.
  71.  
  72. You must have the file "cmex.h" in order to compile this file when "MATLAB" is true.
  73. "cmex.h" is distributed by MathWorks as part of MATLAB.
  74.  
  75. Don't #define MATLAB within your C file; use the Edit:Options:THINK C:Prefix
  76. window instead. E.g. you could type
  77.     #define MATLAB 1
  78. into the Prefix window, or, more conveniently (because it speeds up your
  79. compilations enormously), type
  80.     #include "VideoToolboxMATLAB.pre"
  81. See VideoToolboxMATLAB.c for instructions.
  82.  
  83. The MATLABMain.h header allocates space for QuickDraw globals for use by THINK C
  84. MATLAB projects. It should be #included in the main C file of each THINK C
  85. MATLAB project, i.e. in the C file that contains "main" or "user_fcn". It must
  86. be included in exactly one source file of each project, as the THINK C Linker
  87. will otherwise complain.
  88.  
  89. dgp & dhb.
  90. Copyright 1989-1994 © Denis G. Pelli
  91.  
  92. HISTORY: (omitting changes documented in C files)
  93. 2/20/93 dhb    Added various commonly used headers.  
  94.             Restructured so that only VideoToolbox.h has to be included,
  95.             whether one is creating stand-alone THINK C or code resources
  96.             to be called by MATLAB. Everything that cares is properly conditioned
  97.             by the symbol MATLAB.
  98. 7/9/93    dgp    Changed our convention for the MATLAB symbol, defining it as
  99.             1 or 0 instead of defining or leaving undefined. The advantage of
  100.             this approach is that "MATLAB" can now be used as an argument in an
  101.             ordinary if statement, which is much more readable than #if.
  102. 8/21/93    dhb    Added undefs in #if MATLAB so that memory allocation goes through THINK C 
  103.             library, not as callback. Callbacks would be OK except that the Mathworks 
  104.             forgot to give us one for realloc. This leads to mixing memory managers
  105.              on the same pointers -- bad bad bad.
  106. 9/2/93    dhb    commented out #include <TranslateLinefeeds.h> since it's
  107.             not presently compatible with MATLAB.
  108. 9/2/93    dgp    Moved the NL and NEWLINE macros from Assign.c into this file.
  109. 9/8/93    dgp    Mention VideoToolbox.c.
  110. 9/11/93    dhb,dgp    Define STDIO_INT and STDIO_DOUBLE.
  111. 9/12/93    dhb    Change STDIO_... to PRINTF_... and SCANF_...
  112.             Insert conditional for MATLAB 3.5 vs. 4.x
  113. 9/14/93    dhb    Conditional for MATLAB changed to make symbol match major version number.
  114.             Removed traces of old trying to force 4 byte ints for MATLAB.
  115. 9/14/93    dgp    Moved up inclusion of QuickDraw.h before MATLAB stuff, since cmex.h
  116.             requires it. Fixed typo, changing "#elseif" to "#elif".
  117. 9/15/93    dgp    Edited the comments above, referring to VideoToolbox.c and the new 
  118.             VideoToolboxMATLAB.c.
  119. 9/16/93    dgp    Added contents of former Assign.h.
  120.             Defined MAC_C so that the VideoToolbox.h header may be used with
  121.             Standard C.
  122. 9/16/93    dhb Removed prototype for obsolete GetDateTimeString.
  123. 10/2/93    dgp    Added #include <Errors.h>.
  124. 12/1/93 dgp Now always write "MATLAB" in all caps, since that's the trademarked name.
  125. 12/16/93 dhb Somewhere things got munged.  Conditional for MATLAB version appeared
  126.            before inclusion of cmex, which won't work.  I fixed the order.
  127. 12/16/93 dhb Commented out inclusion of TranslateLineFeeds.h down below.  This
  128.            generates a link error from MATLAB.
  129. 12/29/93 dgp added #include <Packages.h>
  130. 6/12/94  dgp added definition of Apple's new BlockMoveData, for compatibility with
  131.             Apple's old pre-Universal header files.
  132. 6/12/94    dgp #include Strings.h if Universal header files are used.
  133. 7/28/94 dgp Added test for Metrowerks CodeWarrior C.
  134. 9/2/94    dgp #include MacMemory.h
  135. 9/5/94    dgp changed "int" to "short int" in definitions of PRINTF_INT and SCANF_INT for
  136.             MATLAB 4. This is based on common sense, not testing or detailed knowledge.
  137. 3/31/95    dgp    As a gesture of support for Symantec THINK C 8, now define THINK_C.
  138. 5/26/95 dgp Formerly header files whose precompilation depends on the mc68881 or 
  139.         mc68020 THINK C compiler options (i.e. math.h and mc68881.h) were omitted 
  140.         from VideoToolbox.h so that the resulting precompiled header file could be 
  141.         used in projects regardless of those options. However, for Metrowerks CodeWarrior
  142.         there's no advantage to omitting those headers, and a significant increase in
  143.         compile time, as fp.h is recompiled for each file. Since I've switch to
  144.         CodeWarrior, and expect most other users to switch as well, VideoToolbox.h now
  145.         includes math.h or fp.h.
  146. 5/27/95 dgp removed fp.c prototypes because Apple's fp.h now supports both 68k and ppc.
  147. 6/6/95 dgp discarded all references to TranslateLinefeeds.c and TranslateLinefeeds.h, since
  148.         I never got them to work properly, and I don't think they're needed with Metrowerks
  149.         CodeWarrior.
  150. 6/8/95 dgp Made sure that the MATLAB struct "Matrix" is always native aligned.
  151. 6/13/95 dgp define GENERATING68K, GENERATINGPOWERPC, and GENERATING68881 if not already
  152.         defined (as in Apple's latest universal headers). Define GENERATING68020.
  153. 6/14/95    dhb & dgp redefine the assert() macro, redirecting it to PrintfExit, which
  154.         in turn uses mex_error() to report the error. This is needed to get MEX files
  155.         to link properly.
  156. 6/16/95    dhb Fixed MATLAB's SCANF_INT etc. for __MWERKS__.
  157. 6/16/95 dgp moved the definitions of GENERATING68K to the top of this file, so that
  158.         the MATLAB conditionals can use them.
  159. 6/16/95    dhb    & dgp now #include <assert.h>, unless MATLAB is defined, in which case
  160.         we define a MATLAB-compatible version of the assert macro. Just in case,
  161.         leave NDEBUG defined to disable the standard assert macro which may be
  162.         brought in if the user's source files #include <assert.h>.
  163. 6/16/95    dhb    Fixed longstanding bug (in SCANF_INT??).
  164. 6/23/95    dhb    Include prototypes for AfterDark.c and IsFileSharingOn.c.
  165. 7/19/95 dgp Added changes suggested by Stefan Treue, streue@bcm.tmc.edu, for compatibility
  166.         with Symantec C. Eliminated use of //-style comments. Now include math.h
  167.         when compiling for Standard C, i.e. MAC_C is false.
  168. 8/10/95 dgp Include MacMemory.h ONLY for THINK C, not for Symantec C, since I don't
  169.         have any reason to think that Symantec C memory management is bad.
  170. 8/13/95 dgp Removed definition of THINK_C for SYMANTEC_C. It seems better to leave
  171.         the compiler's macros alone. Changed conditionals throughout the VideoToolbox
  172.         to deal with all the special cases: THINK_C, THINK_CPLUS, and SYMANTEC_C.
  173. 3/5/96    dhb Add conditional to prevent inclusion of <fp.h> and instead include <math.h>
  174.         when THINK_C is true.  This is needed to compile under THINK_C 8.  I suspect
  175.         that this used to work because the universal headers variable was < 2.
  176. 4/1/96    dgp removed "MAC_C" requirement for inclusion of fp.h. Tried to make VideoToolbox.h
  177.         more consistent with q_include.h, so both will work separately or together, in
  178.         either order, but I haven't checked whether I succeeded.
  179. */
  180. #pragma once            /*  suppress multiple inclusions of this file */
  181. #ifndef _VIDEOTOOLBOX_    /*  suppress multiple inclusions of this file */
  182. #define _VIDEOTOOLBOX_
  183. /*
  184. Header files that are required for successful compilation of the rest of this
  185. file are marked "required".
  186. */
  187. #if !defined(MAC_C)
  188.     #if THINK_C    || THINK_CPLUS || SYMANTEC_C                            \
  189.         || applec            /* MPW C, presumably with Mac extensions */    \
  190.         || __MWERKS__        /* Metrowerks CodeWarrior C, " */
  191.         /* Set MAC_C to true only if the "pascal" keyword is allowed. */
  192.         #if THINK_C && !SYMANTEC_C
  193.             #if !__option(thinkc)
  194.                 #define MAC_C 0    /* Standard C */
  195.             #endif
  196.         #endif
  197.         #if SYMANTEC_C
  198.             #if __option(ansi_strict)
  199.                 #define MAC_C 0    /* Standard C */
  200.             #endif
  201.         #endif
  202.         #if __MWERKS__
  203.             #if __option(ANSI_strict) || __option(only_std_keywords)
  204.                 #define MAC_C 0    /* Standard C */
  205.             #endif
  206.         #endif
  207.         #if !defined(MAC_C)
  208.             #define MAC_C 1    /* allow Mac C extensions: "pascal", etc. */
  209.         #endif
  210.     #else
  211.         #define MAC_C 0        /* Standard C */
  212.     #endif
  213. #endif
  214. #ifndef SHORT_DOUBLE_OK
  215.     #if SYMANTEC_C
  216.         #define SHORT_DOUBLE_OK 0        /* "short double" not supported by Symantec C */
  217.     #else
  218.         #define SHORT_DOUBLE_OK MAC_C    /* "short double" not allowed by Standard C */
  219.     #endif
  220. #endif
  221. #include <stdio.h>            /*  required */
  222. #include <stdlib.h>
  223. #if MAC_C
  224.     #include <Quickdraw.h>    /*  required */
  225. #endif
  226. /*
  227. The inclusion, above, of Quickdraw.h will result in the inclusion of MixedMode.h
  228. only if the Universal Headers are used, since the Universal Headers and the Mixed
  229. Mode Manager are both new, providing universal support for 68k and ppc Macs.
  230. */
  231. #if defined(__MIXEDMODE__)
  232.     #if defined(GENERATINGPOWERPC) || defined(GENERATING68K)
  233.         #define UNIVERSAL_HEADERS 2    /* version 2 */
  234.     #else
  235.         #define UNIVERSAL_HEADERS 1    /* version 1 */
  236.     #endif
  237. #else
  238.     #define UNIVERSAL_HEADERS 0
  239. #endif
  240.  
  241. /*
  242. Based on Apple's ConditionalMacros.h, so that the VideoToolbox and your sources 
  243. can use these new macros without worrying about whether you've actually got the 
  244. new headers (June '95) in which they are first introduced. This section has no effect if
  245. GENERATINGPOWERPC etc. are already defined. These macros support early versions of
  246. THINK C, which Apple's new headers don't support.
  247. */
  248. #if !defined(GENERATINGPOWERPC) || !defined(GENERATING68K)
  249.     #undef GENERATINGPOWERPC
  250.     #undef GENERATING68K
  251.     #if defined(powerc) || defined(__powerc)
  252.         #define GENERATINGPOWERPC 1
  253.         #define GENERATING68K 0
  254.     #else
  255.         #define GENERATINGPOWERPC 0
  256.         #define GENERATING68K 1
  257.     #endif
  258. #endif
  259. #if GENERATING68K && !defined(GENERATING68881)
  260.     #if defined(applec) || defined(__SC__)
  261.         #ifdef mc68881
  262.             #define GENERATING68881 1
  263.         #endif
  264.     #else
  265.         #if THINK_C && THINK_C==1        /* THINK C 4 */
  266.             #define GENERATING68881 _MC68881_
  267.         #endif
  268.         #if SYMANTEC_C || THINK_CPLUS || (THINK_C && THINK_C>1)    /* THINK C 5,6,7,8, C++, SYMANTEC C,C++ */
  269.             #if __option(mc68881)
  270.                 #define GENERATING68881 1
  271.             #endif
  272.         #endif
  273.         #ifdef __MWERKS__
  274.             #if __MC68881__
  275.                 #define GENERATING68881 1
  276.             #endif
  277.         #endif
  278.     #endif
  279. #endif
  280. #ifndef GENERATING68881
  281.     #define GENERATING68881 0
  282. #endif
  283.  
  284. /* Apple's headers don't define GENERATING68020, but Identify.c and Require.c need it. */
  285. #if GENERATING68K && !defined(GENERATING68020)
  286.     #if defined(applec) || defined(__SC__)
  287.         #ifdef mc68020
  288.             #define GENERATING68020 1
  289.         #endif
  290.     #else
  291.         #if THINK_C && THINK_C==1            /* THINK C 4 */
  292.             #define GENERATING68020 _MC68020_
  293.         #endif
  294.         #if SYMANTEC_C || THINK_CPLUS || (THINK_C && THINK_C>1)    /* Symantec C, THINK C 5,6,7,8 */
  295.             #if __option(mc68020)
  296.                 #define GENERATING68020 1
  297.             #endif
  298.         #endif
  299.         #if __MWERKS__
  300.             #if __MC68020__
  301.                 #define GENERATING68020 1
  302.             #endif
  303.         #endif
  304.     #endif
  305. #endif
  306. #if !defined(GENERATING68020)
  307.     #define GENERATING68020 0
  308. #endif
  309.  
  310. #if !defined(MATLAB)
  311.     #define MATLAB 0
  312. #endif
  313. #if MATLAB
  314.     /*
  315.     This must come after stdlib.h, stdio.h, and QuickDraw.h and before everything
  316.     else. If MATLAB is true then we include the header file cmex.h.  Otherwise we
  317.     define the data types that are normally provided by that header, so that code
  318.     that uses these types may be compiled for use in applications.  It must come
  319.     before we test for version 3 or 4.  The version 3 cmex.h does not define the
  320.     symbol mex_h; version 4 does.  This is what we use to figure out which
  321.     version we are compiling for.  Sound complicated?  Sigh! dhb
  322.     */
  323.     
  324.     #include "cmex.h"
  325.     /* Test for MATLAB 4 or MATLAB 3, and set symbol appropriately. */
  326.     #undef MATLAB
  327.     #ifdef mex_h
  328.         #define MATLAB 4
  329.     #else
  330.         #define MATLAB 3
  331.     #endif
  332.     #if !MAC_C
  333.         #error "MATLAB requires the Macintosh extensions to C."
  334.     #endif
  335.  
  336.     /*
  337.     Undefine the macros that override memory allocation.  MATLAB's implementation
  338.     doesn't work if you use realloc.
  339.     */
  340.     #undef malloc
  341.     #undef calloc
  342.     #undef free
  343.     
  344.     /* Define data types for printf, scanf. */
  345.     #if MATLAB==4                    /* Version 4 */
  346.         #if GENERATING68K
  347.             typedef short int PRINTF_INT;        /* type of arguments to printf et al. */
  348.             typedef long double PRINTF_DOUBLE;
  349.             typedef    int SCANF_INT;                /* type of arguments to scanf et al. */
  350.             typedef double SCANF_DOUBLE;
  351.         #endif
  352.         #if GENERATINGPOWERPC
  353.             typedef int PRINTF_INT;                /* type of arguments to printf et al. */
  354.             typedef double PRINTF_DOUBLE;
  355.             typedef int SCANF_INT;                /* type of arguments to scanf et al. */
  356.             typedef double SCANF_DOUBLE;
  357.         #endif
  358.     #endif
  359.     #if THINK_C || THINK_CPLUS || SYMANTEC_C    /* Declare our own QuickDraw globals, allocated by MATLABMain.h */
  360.         extern THINK_C_QD mex_qd;
  361.         #define qd mex_qd
  362.     #else
  363.         #define mex_qd qd
  364.     #endif
  365. #else
  366.     typedef long int INT;
  367.     #if SHORT_DOUBLE_OK
  368.         typedef short double DOUBLE;/* not allowed by Standard C */
  369.     #else
  370.         typedef double DOUBLE;
  371.     #endif
  372.     typedef int PRINTF_INT;            /* type of arguments to printf et al. */
  373.     typedef double PRINTF_DOUBLE;
  374.     typedef int SCANF_INT;            /* type of arguments to scanf et al. */
  375.     typedef double SCANF_DOUBLE;
  376.     #if SHORT_DOUBLE_OK
  377.         #if PRAGMA_ALIGN_SUPPORTED || __MWERKS__
  378.             #pragma options align=native
  379.         #endif
  380.         typedef struct {
  381.             char *name;
  382.             INT type;
  383.             INT m;
  384.             INT n;
  385.             DOUBLE *pr;
  386.             DOUBLE *pi;
  387.         } Matrix;
  388.         #if PRAGMA_ALIGN_SUPPORTED || __MWERKS__
  389.             #pragma options align=reset
  390.         #endif
  391.     #endif
  392. #endif
  393.  
  394. /*  Standard C headers */
  395. #if MATLAB
  396.     /* The <assert.h> macro requires modification to work in a MATLAB shared library. */
  397.     #define NDEBUG        /* disable the standard assert.h macro */
  398.     #undef assert
  399.     #define assert(x)    if(!(x)){\
  400.         PrintfExit("Assertion (" #x ") failed at %s:%d\n",__FILE__,__LINE__);\
  401.     }
  402. #else
  403.     #include <assert.h>
  404. #endif
  405. #include <ctype.h>
  406. #include <float.h>
  407. #include <limits.h>
  408. #include <stdlib.h>
  409. #include <string.h>
  410. #include <time.h>
  411. #if !defined(__MATH__) && (UNIVERSAL_HEADERS>=2) && !THINK_C
  412.     #include <fp.h>
  413. #else
  414.     #if GENERATINGPOWERPC || GENERATING68881
  415.         /* as advised by math.h, we don't enable these if using 8-byte doubles on 68k */
  416.         #undef _NOERRORCHECK_
  417.         #undef _INLINE_FPU_CALLS_
  418.         #define _NOERRORCHECK_ 1        /* encourage use of 8881 intrinsic functions */
  419.         #define _INLINE_FPU_CALLS_ 1    /* encourage use of 8881 intrinsic functions */
  420.     #endif
  421.     #include <math.h>
  422.     #if !defined(__FP__)    /* make sure that math.h hasn't included fp.h */
  423.         #undef round
  424.         #define round(x) floor(0.5+(x))    /* used by many VideoToolbox routines */
  425.     #endif
  426. #endif
  427.  
  428. /*  Macintosh headers */
  429. #if MAC_C
  430.     #if THINK_C || THINK_CPLUS || SYMANTEC_C
  431.         #include <console.h>
  432.     #endif
  433.     #include <Devices.h>
  434.     #include <Errors.h>
  435.     #include <Events.h>
  436.     #include <FixMath.h>
  437.     #include <Fonts.h>
  438.     #if UNIVERSAL_HEADERS>2
  439.         #include <Gestalt.h>    /* Apple abbreviated the filename */
  440.     #else
  441.         #include <GestaltEqu.h>
  442.     #endif
  443.     #include <Memory.h>
  444.     #include <Menus.h>
  445.     #include <OSEvents.h>
  446.     #include <OSUtils.h>    /*  required */
  447.     #include <Packages.h>
  448.     #include <Palettes.h>
  449.     #if (THINK_C || THINK_CPLUS || SYMANTEC_C)
  450.         #include <profile.h>/* only needed if you want timing info */
  451.     #endif
  452.     #include <QDOffscreen.h>
  453.     #include <Resources.h>
  454.     #include <Retrace.h>    /*  required */
  455.     #if __MWERKS__
  456.         #include <SIOUX.h>
  457.     #endif
  458.     #include <Slots.h>
  459.     #include <Sound.h>
  460.     #if THINK_C && !UNIVERSAL_HEADERS
  461.         #include <pascal.h>    /* CtoPStr() and PtoCStr() */
  462.         #ifndef c2pstr
  463.             #define c2pstr(s) CtoPstr(s)
  464.             #define p2cstr(s) PtoCstr(s)
  465.         #endif
  466.     #else
  467.         #include <Strings.h>/* c2pstr() and p2cstr() */
  468.         #define CtoPstr c2pstr
  469.         #define PtoCstr p2cstr
  470.     #endif
  471.     #include <Timer.h>        /*  required */
  472.     #include <ToolUtils.h>
  473.     #include <Traps.h>
  474.     #include <Video.h>
  475.     #include <Windows.h>    /*  required */
  476.     /*
  477.     Old Memory.h header files, before Apple's Universal Headers, don't define the new
  478.     BlockMoveData(), so we do it here, to retain compability with the old header files.
  479.     */
  480.     #if !UNIVERSAL_HEADERS
  481.         #pragma parameter BlockMoveData(__A0,__A1,__D0)
  482.         extern pascal void BlockMoveData(const void *srcPtr,void *destPtr,Size byteCount)=0xA22E;
  483.     #endif
  484. #endif
  485.  
  486. /*
  487. This redefines the standard C functions, malloc, etc. to instead call Apple's
  488. corresponding routines, e.g. NewPtr. The THINK C memory management routines are 
  489. poor because they are bad about freeing space, tending to fragment the free space. 
  490. */
  491. #if THINK_C && !defined(SYMANTEC_C)
  492.     #include "MacMemory.h"
  493. #endif
  494.  
  495. /*
  496. MATLAB AND THE NEWLINE CHARACTER
  497. In most C environments the newline character is '\n' (ascii 10). In Apple's
  498. wisdom they chose to separate lines in Macintosh files with the ascii 13
  499. character, which is usually called the return character '\r'. Standard C
  500. specifies that the stdio library will use '\n' as the newline character. This
  501. potentially creates a compatibility problem between Mac C programs and C
  502. programs written for the rest of the world's computers, since one wants any text
  503. files they produce to be appropriate to the local environment. Both MPW and
  504. THINK C resolve the problem behind the scenes, but they do it in different ways.
  505. MPW redefines the association between symbolic names and character codes, making
  506. '\n' be 13 and '\r' be 10. THINK C instead modifies the stdio library so that
  507. reads and writes to a "text" (i.e. not binary) stream are translated, exchanging
  508. character codes 10 and 13. Both solutions work. However, when we use THINK C to
  509. create code resources for MATLAB we are forced to use the MPW stdio library that
  510. is built into MATLAB. Unfortunately this bypasses both compilers' fixes to the
  511. newline problem. The problem affects every single text i/o operation, e.g. every
  512. printf and scanf. Alas, there is no way to get the pre-processor to redefine /n
  513. and /r.
  514.  
  515. Our quick fix is to create a macro called NL that is normally defined as the
  516. newline string "\n", but which is instead defined as "\015" (i.e. ascii 13) when
  517. MATLAB is true. Programs such as Assign.c that have replaced all instances of
  518. "\n" by NL will then work whether or not MATLAB is true. The obvious drawback is
  519. that this quick solution requires these modifications to the source files.
  520. */
  521. #if MATLAB && THINK_C    /* Quick fix */
  522.     #define NL "\r"
  523.     #define NEWLINE '\r'
  524. #else
  525.     #define NL "\n"        /* the standard new-line string */
  526.     #define NEWLINE '\n'
  527. #endif
  528.  
  529. /*
  530. TRUE and FALSE
  531. */
  532. #ifndef TRUE
  533.     #define FALSE    0
  534.     #define TRUE    1
  535. #endif
  536.  
  537. /*
  538. NAN & INF
  539. If you're using NAN and INF you'll be interested in the IsNan(), IsInf(), and
  540. IsFinite() definitions & prototypes below. 
  541. Apple's fp.h header defines isnan() and isfinite().
  542. Apple's header files math.h and fp.h both define HUGE_VAL and pi.
  543. fp.h also defines INFINITY, NAN, isfinite(), and isnan().
  544. */
  545. #if !defined(INF)
  546.     #define INF HUGE_VAL    /* HUGE_VAL is defined in math.h and fp.h */
  547. #endif
  548. #if !defined(NAN)
  549. /*    #define NAN    (0.0/0.0)    */    /* evaluated at runtime */
  550.     #define NAN    Nan            /* global defined in Nan.c */
  551. #endif
  552.  
  553. /*
  554. NUMERICAL CONSTANTS
  555. It's sad to say, but THINK C 5.02 loses two bits of precision converting between
  556. doubles and ascii text, in either direction. Thus you will obtain more accurate
  557. results by computing the numerical constants below at runtime rather than using
  558. these predefined constants. The ANSI Numerical C Extensions group is moving to
  559. require C compilers to preserve precision, so there is hope for the future. Of
  560. course most applications would never notice a loss of two bits precision out of
  561. the total double precision given by the 64 bits in the mantissa.
  562. */
  563. #if !defined(PI)
  564.     #if UNIVERSAL_HEADERS>=2
  565.         #define PI        pi                        /* pi is defined in math.h and fp.h */
  566.     #else
  567.         #define PI        3.1415926535897932385    /* computed in Mathematica */
  568.     #endif
  569. #endif
  570. #if !defined(LOGPI)
  571.     #define LOGPI    1.14472988584940017414    /* computed in Mathematica */
  572. #endif
  573. #if !defined(LOG2)
  574.     #define LOG2    0.69314718055994530942    /* computed in Mathematica */
  575. #endif
  576. #if !defined(LOG10)
  577.     #define LOG10    2.30258509299404568402    /* computed in Mathematica */
  578. #endif
  579.  
  580. #if MAC_C
  581.     /*
  582.     CLUTSIZE
  583.     Inline code that returns the same answer as GDClutSize(device).
  584.     */
  585.     #define GDCLUTSIZE(device) (gdClutSizeTable[(**(**(device)).gdPMap).pixelSize])
  586.     
  587.     /*  Commented out, because its answer is misleading when in 16-bit or 32-bit mode. */
  588.     /* #define GDCOLORS(device) ((**(**(**device).gdPMap).pmTable).ctSize+1) */
  589. #endif
  590.  
  591. /*
  592. FIXED POINT ARITHMETIC
  593. Apple defines a handy data type called Fixed that is stored in a long, but is
  594. assumed to have a decimal point in the middle. Many operations, e.g. adding two
  595. Fixed numbers or multiplying or dividing a Fixed by an integer, can be performed
  596. directly. To multiply or divide two Fixed numbers use Apple's FixMul() and
  597. FixDiv(). FixRatio(n,m) returns the Fixed ratio of two integers. Macintosh C
  598. compilers define double in various ways, depending on whether a floating point
  599. unit is to be used. The Apple-provided routines for doing type conversion to and
  600. from Fixed are only appropriate if you are NOT using the floating point unit.
  601. The ones defined below are faster and work with or without the FPU.
  602. */
  603. #define LongToFix(x) ((long)(x)<<16)
  604. #define FixToLong(x) ((x)>>16)
  605. #define DoubleToFix(x) ((long)((x)*65536.+0.5))
  606. #define FixToDouble(x) ((double)(x)*(1./65536.))
  607.  
  608. #if MAC_C
  609.     /*
  610.     StackGrow(n) increases the stack allocation by n bytes. You'll also want to use
  611.     Apple's StackSpace(), declared in Memory.h, that returns the number of bytes 
  612.     allocated for the stack.
  613.     */
  614.     #define StackGrow(extraBytes) SetApplLimit(GetApplLimit()-(extraBytes))
  615. #endif
  616.  
  617. #if MAC_C
  618.     /* AfterDark.c */
  619.  
  620.     OSErr AfterDarkEnable(void);
  621.     OSErr AfterDarkDisable(void);
  622. #endif
  623.  
  624. /* Assign.c */
  625.  
  626. #define ASSIGN_DIMS 3        /* Feel free to increase or decrease ASSIGN_DIMS. */
  627. typedef struct {
  628.     short type;
  629.     unsigned sizedOnce:1;    /* dim[] is meaningful */
  630.     unsigned sized:1;        /* dim[] is final */
  631.     unsigned malloced:1;    /* allocated by malloc */
  632.     char *name;
  633.     void *ptr;                /* for array, address of element zero */
  634.     long dim[ASSIGN_DIMS];    /* zero indicates a scalar */
  635.     long firstElement;        /* for 1-d array, index of first array element. Usually 0 */
  636.     const char *comment;    /* text string, or NULL */
  637. } Description;
  638. enum{assignReportUnknown=1,assignNoHexInts=2,assignHexFloats=4
  639.     ,assignNoComment=8,assignNoPrintfExit=0x10
  640.     ,assignEchoAssignments=0x20,assignEchoComments=0x40,assignEchoFile=0x80
  641. };
  642. enum {assignMemoryError=-1,assignTypeError=-2
  643.     ,assignVariableError=-3,assignUnknownVariableError=-4
  644.     ,assignSubscriptError=-5,assignSubscriptBoundsError=-6
  645.     ,assignEqualsError=-7,assignConstantError=-8,assignHexError=-9
  646.     ,assignSemicolonError=-10,assignFileError=-11
  647.     ,assignInconsistentDescriptionsError=-12,assignUnequalDataError=-13
  648.     ,assignInconsistentDimensionsError=-14
  649.     ,assignCouldntFindDescription=-15
  650. };
  651. enum{charType=1,unsignedCharType,shortType,unsignedShortType
  652.     ,longType,unsignedLongType
  653.     ,floatType
  654.     #if SHORT_DOUBLE_OK
  655.         ,shortDoubleType
  656.     #endif
  657.     ,doubleType
  658.     ,charPtrType,unsignedCharPtrType,shortPtrType,unsignedShortPtrType
  659.     ,longPtrType,unsignedLongPtrType
  660.     ,floatPtrType
  661.     #if SHORT_DOUBLE_OK
  662.         ,shortDoublePtrType
  663.     #endif
  664.     ,doublePtrType
  665.     ,stringType,unknownType
  666. };
  667. FILE *OpenCalFileRead(char *filename);
  668. FILE *OpenCalFileReadAndCheck(char *filename);
  669. FILE *OpenCalFileWrite(char *filename);
  670. void AppendDescriptions(Description **d,Description *s);
  671. void CopyDescriptions(Description *d,Description *s);
  672. Description *AllocateDescriptions(long n);
  673. void FreeDescriptions(Description *d);
  674. long NumberOfDescriptions(Description *d);
  675. Description NullDescription(void);
  676. int IsNullDescription(Description d);
  677. #define IsNullDescription(d) ((d).type==0)
  678. int AssignmentLineWasBlank(void);
  679. int UnequalDescribedVars(Description d1[],Description d2[],short flags);
  680. int UnequalDescribedVarPair(Description *d1,Description *d2,short flags);
  681. int CopyDescribedVars(Description d1[],Description d2[],short flags);
  682. int CopyDescribedVarPair(Description *d1,Description *d2,short flags);
  683. long InitializeADescribedVar(Description *d,short flags);
  684. long InitializeDescribedVars(Description d[],short flags);
  685. long FindDescribedDim(Description d[],void *ptr,int i,short flags);
  686. long FindDescription(Description d[],void *ptr,short flags);
  687. void FreeADescribedVar(Description *d,short flags);
  688. void FreeDescribedPtrVars(Description d[],short flags);
  689. void FreeDescribedVars(Description d[],short flags);
  690. void KeepDescribedVars(Description d[],short flags);
  691. void KeepADescribedVar(Description *d,short flags);
  692. long PrintAnAssignment(FILE *stream,Description *d,short flags);
  693. long PrintAssignments(FILE *stream,Description d[],short flags);
  694. long PrintAssignmentsToFile(const char *filename,Description d[],short flags);
  695. long ReadAssignmentLine(FILE *stream,Description d[],short flags);
  696. long ReadAssignmentBlock(FILE *stream,Description d[],short flags);
  697. long ReadAssignmentStream(FILE *stream,Description d[],short flags);
  698. long ReadAssignmentFile(const char *filename,Description d[],short flags);
  699. Description Describe(short type,void *ptr,char *name,const char *comment);
  700. Description DescribeArray(short type,void *ptr,char *name,const char *comment,...);
  701. Description DescribeFirstLast(short type,void *ptr,char *name
  702.     ,const char *comment,long firstElement,long lastElement);
  703.  
  704. #if MAC_C
  705.     /* AtExitToShell.c */
  706.     
  707.     int AtExitToShell(void(*userFunctionPtr)(void));
  708. #endif
  709.  
  710. /* Binomial.c */
  711.  
  712. long    BinomialSample(double p,long n);
  713. int        BinomialSampleQuickly(int n);
  714. double    BinomialLowerBound(double P,long k,long n);
  715. double    BinomialUpperBound(double P,long k,long n);
  716. double    BinomialPdf(double p,long k,long n);
  717. double    Binomial(double p,long k,long n);
  718. double    IncompleteBeta(double x,double a,double b);
  719. double    InverseBinomial(double P,long k,long n);
  720. double    InverseIncompleteBeta(double p,double a,double b);
  721.  
  722. /* BreakLines.c */
  723.  
  724. char *BreakLines(char *string,long lineLength);
  725. void PrintWrappedText(FILE *stream,const char *s);
  726. void PrintWrappedTextToFile(const char *filename,const char *s);
  727. void PrintWrappedComment(FILE *stream,const char *s);
  728. void PrintWrappedCommentToFile(const char *filename,const char *s);
  729.  
  730. #if MAC_C
  731.     /* CardSlot.c */
  732.     
  733.     OSErr    CardSlot(char *cardName);
  734.     
  735.     /* CenterRectInRect.c */
  736.     
  737.     void CenterRectInRect(Rect *moveableRectPtr,Rect *fixedRectPtr);
  738.     void OffsetRectTile(Rect *r,int nx,int ny);
  739.     Boolean IsRectInRect(Rect *r,Rect *R);
  740.     void ShrinkRect(Rect *r,int hDivisor,int vDivisor);
  741.     void ExpandRect(Rect *r,double hMag,double vMag);
  742.     void ExpandAndOffsetRect(Rect *r,double hMag,double vMag,double hOffset,double vOffset);
  743.     void LocalToGlobalRect(Rect *r);
  744.     void GlobalToLocalRect(Rect *r);
  745.  
  746. #endif
  747.  
  748. /* ChiSquare.c */
  749.  
  750. double    PChiSquare (double chiSquare,int n);
  751.  
  752. /* Choose.c */
  753.  
  754. #if !MAC_C
  755.     #define Boolean unsigned char
  756. #endif
  757. int Choose(int defaultChoice,const char *query,char *choices[],int n);
  758. char *ChoiceStr(char *choices[],int n);
  759. int MultipleChoice(short defaultChoice,short n,char *choices[]);
  760. Boolean YesOrNo(Boolean defaultAnswer);
  761. extern char *noYes[];
  762. #if !MAC_C
  763.     #undef Boolean
  764. #endif
  765.  
  766. #if MAC_C
  767.     /* ChooseScreen.c */
  768.     
  769.     int ChooseScreen(int screen,const char *question);
  770.  
  771.     /* ConvolveX.c */
  772.     
  773.     void    ConvolveX(double f[],int dim,BitMap *srcBits,BitMap *dstBits,
  774.                 Rect *srcRectPtr,Rect *dstRectPtr);
  775.  
  776.     /* ConvolveY.c */
  777.     
  778.     void ConvolveY(double f[],int dim,BitMap *srcBits,BitMap *dstBits,
  779.                 Rect *srcRectPtr,Rect *dstRectPtr);
  780.     
  781.     /* CopyBitsQuickly.c */
  782.     
  783.     enum{addOverQuickly=40,addOverParallel=40,mulOver};
  784.     int    CopyBitsQuickly(BitMap *srcBits,BitMap *dstBits
  785.         ,Rect *srcRectPtr,Rect *dstRectPtr,long srcMode,RgnHandle maskRgn);
  786.     
  787.     /* CopyQuickDrawGlobals.c */
  788.     
  789.     void CopyQuickDrawGlobals(void);
  790.     #define CopyQuickdrawGlobals CopyQuickDrawGlobals    /*  old spelling */
  791.     
  792.     /* CopyWindows.c */
  793.     
  794.     enum{copyLiterally=0x10000,copyColorize=0x20000};
  795.     enum{srcCopyLiterally=srcCopy+copyLiterally,addOverLiterally=addOver+copyLiterally
  796.         ,addOverParallelLiterally=addOverParallel+copyLiterally
  797.         ,mulOverLiterally=mulOver+copyLiterally};
  798.     int CopyWindows(CWindowPtr srcWindow,CWindowPtr dstWindow
  799.         ,Rect *srcRectPtr,Rect *dstRectPtr,long srcMode,RgnHandle maskRgn);
  800.  
  801.     /* CreateTrialSnds.c */
  802.     
  803.     void CreateTrialSnds(void);
  804. #endif
  805.  
  806. /* DatedString.c */
  807.  
  808. char    *DatedString(unsigned long seconds);
  809.  
  810. #if MAC_C
  811.     /* DrawPrintf.c */
  812.     
  813.     void DrawPrintf(char *s, ...);
  814. #endif
  815.  
  816. /* Exponential.c */
  817.  
  818. double ExponentialPdf(double x);
  819.  
  820. /* ffprintf.c */
  821.  
  822. int ffprintf(FILE *stream[2],char *format,...);
  823.  
  824. #if MAC_C
  825.     /* FlushCacheRange.c */
  826.     
  827.     void FlushCacheRange (void *address, unsigned long count);
  828.     
  829.     /* GDOpenWindow.c */
  830.     
  831.     void AddExplicitPalette(WindowPtr window);
  832.     void RemovePalette(WindowPtr window);
  833.     WindowPtr GDOpenWindow1(GDHandle device);
  834.     void GDDisposeWindow1(WindowPtr window);
  835.     CWindowPtr GDOpenWindow(GDHandle device);
  836.     void GDDisposeWindow(CWindowPtr myWindow);
  837.     void GDGrayColorTable(GDHandle device);
  838.     void SwapWindowExplicitMode(CWindowPtr window,Boolean *explicit);
  839.     BitMap *GetBitMapPtr(CWindowPtr window);
  840.     Boolean IsGWorldPtr(CWindowPtr window);
  841.     Boolean IsGrafPtr(CWindowPtr window);
  842.     
  843.     /* GDPrintf.c */
  844.     
  845.     void GDPrintf(char *s, ...);
  846.     
  847.     /* GDTime.c */
  848.     
  849.     double GDFrameRate(GDHandle device);
  850.     double GDMovieRate(GDHandle device,int quickly);
  851.     double GDMovieSize(GDHandle device,int quickly);
  852.     double GDVBLRate(GDHandle device);
  853.     double TickRate(void);
  854.     typedef OSErr (*SetEntriesFunction)(GDHandle device,short start,short count
  855.         ,ColorSpec *aTable);
  856.     OSErr GDTimeClut(GDHandle device,SetEntriesFunction function,short clutEntries
  857.         ,double *sPtr,double *framesPtr,double *missingFramesPtr,double *frameRatePtr);
  858.     
  859.     /* GDVideo.c */
  860.     
  861.     #define MAX_SCREENS 8
  862.     OSErr DriverGestalt(int refNum,OSType driverGestaltSelector,unsigned long *driverGestaltResponsePtr);
  863.     OSErr GDGestalt(GDHandle device,OSType driverGestaltSelector,unsigned long *driverGestaltResponsePtr);
  864.     Boolean GDGestaltIsOn(GDHandle device);
  865.     char  *GDCardName(GDHandle device);
  866.     extern short gdClutSizeTable[33];
  867.     short GDClutSize(GDHandle device);
  868.     long GDColors(GDHandle device);
  869.     OSErr GDControl(int refNum,int csCode,Ptr csParamPtr);
  870.     short GDDacSize(GDHandle device);
  871.     OSErr GDDirectSetEntries(GDHandle device,short start,short count,ColorSpec *aTable);
  872.     OSErr GDDisposeGamma(GDHandle device);
  873.     OSErr GDGetDisplayMode(GDHandle device,unsigned long *displayModeIDPtr
  874.         ,unsigned short *modePtr,unsigned short *pagePtr,Ptr *baseAddrPtr);
  875.     OSErr GDGetNextResolution(GDHandle device,unsigned long previousDisplayModeID
  876.         ,unsigned long *displayModeIDPtr,unsigned long *horizontalPixelsPtr
  877.         ,unsigned long *verticalLinesPtr,Fixed *refreshRatePtr
  878.         ,unsigned short *maxDepthModePtr);
  879.     OSErr GDGetDefaultGamma(GDHandle device,GammaTbl **gammaTbl);
  880.     OSErr GDGetDefaultMode(GDHandle device,short *modePtr);
  881.     OSErr GDGetDelay(GDHandle device,Boolean *dontWaitForVBLPtr,double *nanosecondsPtr);
  882.     OSErr GDGetEntries(GDHandle device,short start,short count,ColorSpec *aTable);
  883.     OSErr GDGetGamma(GDHandle device,GammaTbl **myGammaTblHandle);
  884.     OSErr GDGetGray(GDHandle device,Boolean *flagPtr);
  885.     OSErr GDGetInterrupt(GDHandle device,Boolean *flagPtr);
  886.     OSErr GDGetMode(GDHandle device,short *modePtr,short *pagePtr,Ptr *baseAddrPtr);
  887.     OSErr GDGetPageBase(GDHandle device,short page,Ptr *baseAddrPtr);
  888.     OSErr GDGetPageCnt(GDHandle device,short mode,short *pagesPtr);
  889.     OSErr GDGrayPage(GDHandle device,short page);
  890.     Boolean GDHasMode(GDHandle device,short mode,short *pixelSizePtr,short *pagesPtr);
  891.     short GDModePixelSize(GDHandle device,short mode);
  892.     unsigned char *GDName(GDHandle device);
  893.     char *GDNameStr(GDHandle device);
  894.     ColorSpec *GDNewLinearColorTable(GDHandle device);
  895.     short GDPixelSize(GDHandle device);
  896.     OSErr GDPrintGammaTable(FILE *o,GDHandle device);
  897.     OSErr GDReset(GDHandle device,short *modePtr,short *pagePtr,Ptr *baseAddrPtr);
  898.     OSErr GDRestoreDeviceClut(GDHandle device);
  899.     OSErr GDRestoreGamma(GDHandle device);
  900.     OSErr GDSaveGamma(GDHandle device);
  901.     OSErr GDSetDefaultMode(GDHandle device,short mode);
  902.     OSErr GDSetDelay(GDHandle device,Boolean dontWaitForVBL,double nanoseconds);
  903.     OSErr GDSetEntries(GDHandle device,short start,short count,ColorSpec *aTable);
  904.     OSErr GDSetEntriesByType(GDHandle device,short start,short count,ColorSpec *table);
  905.     OSErr GDSetEntriesByTypeHighPriority(GDHandle device,short start,short count
  906.         ,ColorSpec *table);
  907.     OSErr GDSetGamma(GDHandle device,GammaTbl *myGammaTblPtr);
  908.     OSErr GDSetGray(GDHandle device,Boolean flag);
  909.     OSErr GDSetInterrupt(GDHandle device,Boolean flag);
  910.     OSErr GDSetMode(GDHandle device,short mode,short page,Ptr *baseAddrPtr);
  911.     OSErr GDSetPageDrawn(GDHandle device,short page);
  912.     OSErr GDSetPageShown(GDHandle device,short page);
  913.     OSErr GDStatus(int refNum,int csCode,Ptr csParamPtr);
  914.     OSErr GDSwitchMode(GDHandle device,short mode,long displayModeID,short page,Ptr *baseAddrPtr);
  915.     short GDType(GDHandle device);
  916.     OSErr GDUncorrectedGamma(GDHandle device);
  917.     int GDVersion(GDHandle device);
  918.     int PatchMacIIciVideoDriver(void);
  919.     Boolean IsPCIMac(void);
  920.     void GDRestoreBlackAndWhite(GDHandle device);
  921.     
  922.     /* GetClicks.c */
  923.     
  924.     short    GetClicks(void);
  925.     short    GetNextEventOrQuit(int mask,EventRecord *eventPtr);
  926.  
  927.     /* GetScreenDevice.c */
  928.     
  929.     GDHandle    GetScreenDevice(int n);
  930.     int            GetScreenIndex(GDHandle device);
  931.     GDHandle    SlotToScreenDevice(int n);
  932.     GDHandle    GetDeviceByRefNum(int n);
  933.     short int    GetDeviceSlot(GDHandle device);            /* gives nonsense on PCI bus */
  934.     char        *GetDeviceSlotName(GDHandle device);    /* works on NuBus, PCI bus, and no bus */
  935.     GDHandle    GetWindowDevice(WindowPtr theWindow);
  936.     GDHandle    GetRectDevice(Rect *r);
  937.  
  938. #endif
  939.  
  940. /* GetTimeDateString.c */
  941.  
  942. char *GetTimeDateString(time_t t);
  943.  
  944. #if MAC_C
  945.     /* GetVersionString.c */
  946.  
  947.     char *GetVersionString(void);
  948.  
  949.     /* GetVoltage.c */
  950.     
  951.     double    VoltsDuringFrame(double frames);
  952.     double    GetVoltage(short channel,double *gainPtr,double *frequencyPtr,long n
  953.                 ,double *sdPtr);
  954.     short    GetVoltages(short channel,double *gainPtr,double *frequencyPtr,long *nPtr
  955.                 ,unsigned short readings[],double *voltDeltaPtr,double *voltZeroPtr);
  956.     short    InitiateVoltageSampling(short channel,double *gainPtr,double *frequencyPtr
  957.                 ,double *voltDeltaPtr,double *voltZeroPtr);
  958.     short    RetrieveVoltages(long *nPtr,unsigned short readings[]);
  959.     int        ForeRunnerSlot(void);
  960.     enum{voltageBufferOverflow=1<<0,voltageOverflow=1<<1,voltageUnderflow=1<<2};
  961. #endif
  962.  
  963. /* HexToBinary.c */
  964.  
  965. int HexToBinary(char *string,void *ptr);
  966. char *BinaryToHex(size_t n,void *ptr,char *string);
  967.  
  968. #if MAC_C
  969.     /* HideMenuBar.c */
  970.     
  971.     void    HideMenuBar(void);
  972.     void    ShowMenuBar(void);
  973.     void SquareCorners(GDHandle device);
  974.     void RestoreCorners(GDHandle device);
  975.     void UnclipScreen(GDHandle device);
  976.     void RestoreScreenClipping(GDHandle device);
  977.     
  978.     /* Identify.c */
  979.     
  980.     char *IdentifyApplication(void);
  981.     char *IdentifyCompiler(void);
  982.     char *IdentifyGreenwichMeanTime(void);
  983.     char *IdentifyMachine(void);
  984.     char *IdentifyModel(void);
  985.     char *IdentifyOwner(void);
  986.     char *IdentifyVideo(GDHandle device);
  987.     char *IdentifyVM(void);
  988.     
  989.     /* ImageStatistics */
  990.  
  991.     double ImageEnergy(GWorldPtr aWorld,Rect *aRect,double background);
  992.     void ImageStatistics(GWorldPtr world,Rect *rect
  993.         ,long *minPtr,long *maxPtr,double *meanPtr,double *meanSquarePtr);
  994.  
  995.     /* InstallGestaltValue.c */
  996.  
  997.     OSErr InstallGestaltValue(OSType selector,long response);
  998.  
  999.     /* IsCmdPeriod.c */
  1000.     
  1001.     Boolean IsCmdPeriod(EventRecord *event);
  1002.  
  1003.     /* IsFileSharingOn.c */
  1004.  
  1005.     Boolean IsFileSharingOn(void);
  1006.     OSErr KillFileSharing(void);
  1007.  
  1008. #endif
  1009.  
  1010. /* IsNan.c */
  1011.  
  1012. int IsNan(double x);
  1013. int IsInf(double x);
  1014. #ifndef IsFinite    /* neither NAN nor ±INF */
  1015.     #define IsFinite(x) \
  1016.     (sizeof(x)>8?    \
  1017.     ((*(short *)&(x) & 0x7FFF)!=0x7FFF)        /* 10 or 12 byte double */\
  1018.     :((*(short *)&(x) & 0x7FF0)!=0x7FF0))    /* 8 byte double */
  1019. #endif
  1020.  
  1021. #if MAC_C
  1022.     /* kbhit.c */
  1023.     
  1024.     int    kbhit(void);
  1025.     int    getcharUnbuffered(void);
  1026.  
  1027.     /* KillEveryoneButMe.c */
  1028.     
  1029.     OSErr KillEveryoneButMe(void);
  1030. #endif
  1031.  
  1032. /* Log2L.c */
  1033.  
  1034. long Log2L(unsigned long j);
  1035.  
  1036. #if MAC_C
  1037.     
  1038.     /* MaximizeConsoleHeight.c */
  1039.     
  1040.     void MaximizeConsoleHeight(void);
  1041. #endif
  1042.  
  1043. /* Mean.c */
  1044.  
  1045. double Mean(double x[],long n,double *sdPtr);
  1046. double MeanF(float x[],long n,double *sdPtr);
  1047. double MeanB(char x[],long n,double *sdPtr);
  1048. double MeanUB(unsigned char x[],long n,double *sdPtr);
  1049. double MeanW(short x[],long n,double *sdPtr);
  1050. double MeanUW(unsigned short x[],long n,double *sdPtr);
  1051. double MeanL(long x[],long n,double *sdPtr);
  1052. double MeanUL(unsigned long x[],long n,double *sdPtr);
  1053.  
  1054. /* Nan.c */
  1055. extern const short __NAN[];
  1056. #define Nan (*(double *)__NAN)
  1057.  
  1058. #if MAC_C
  1059.     /* NoiseFill.c */
  1060.     
  1061.     int NoiseFill(CWindowPtr window,Rect *r,double dx,double dy,Boolean randomPhase);
  1062.     int NoiseFillBits(PixMap *bits,Rect *r,double dx,double dy,Boolean randomPhase);
  1063.     int MakeNoise1(double dx,double dy,Boolean randomPhase,PixMap *bits);    /* Obsolete */
  1064.     
  1065.     /* NoisePdfFill.c */
  1066.     
  1067.     OSErr NoisePdfFill(GWorldPtr world,Rect *rectPtr
  1068.         ,int pdf,double *meanPtr,double *sdPtr,int min,int max);
  1069.     OSErr NoisePdfAdd(GWorldPtr world,Rect *rectPtr
  1070.         ,int pdf,double *meanPtr,double *sdPtr,int min,int max);
  1071.     enum{kBinaryPdf=0,kBinomialPdf,kGaussianPdf,kUniformPdf};
  1072. #endif
  1073.  
  1074. /* Normal.c */
  1075.  
  1076. double NormalPdf(double x);
  1077. double Normal(double x);
  1078. double InverseNormal(double p);
  1079. double NormalSample(void);
  1080. double Normal2DPdf(double r);
  1081. double Normal2D(double r);
  1082. double InverseNormal2D(double p);
  1083. double Normal2DSample(void);
  1084. double InverseNormal2DPdf(double p);
  1085. void BoundedNormalIntegers(short *distribution,long n,double mean,double sd
  1086.     ,short min,short max);
  1087.  
  1088. /* nrand.c */
  1089.  
  1090. unsigned long nrand(unsigned long n);
  1091.  
  1092. /* OpenDataFiles.c */
  1093.  
  1094. unsigned long OpenDataFiles(FILE **inPtr,FILE **outPtr
  1095.                     ,char *inName,char *outName);
  1096.  
  1097. /* OpenPreferencesFolder.c */
  1098.  
  1099. #if !MAC_C
  1100.     #define OSErr short
  1101. #endif
  1102. OSErr OpenPreferencesFolder(void);
  1103. OSErr ClosePreferencesFolder(void);
  1104. OSErr OpenPreferencesWD(short *wdRefNumPtr);
  1105. #if !MAC_C
  1106.     #undef OSErr
  1107. #endif
  1108.  
  1109. #if MAC_C
  1110.     /*    PixMapToPICT.c */
  1111.  
  1112.     void PixMapToPICT(char *filename,PixMap **pm,Rect *rectPtr
  1113.         ,int pixelSize,ColorTable **cTable);
  1114.  
  1115.     /*    PixMapToPostScript.c */
  1116.     
  1117.     void WindowToEPS(CWindowPtr window,char *filename,Rect *rectPtr
  1118.         ,Rect *pageRectPtr,double cellsPerInch,int grayLevels,float reflectance[256]);
  1119.     void PixMapToEPS(char *filename,PixMap **pm,Rect *rectPtr
  1120.         ,Rect *pageRectPtr,double cellsPerInch,int grayLevels);
  1121.     void PixMapToPostScript(char *filename,PixMap **pm,Rect *rectPtr
  1122.         ,Rect *pageRectPtr,double cellsPerInch,int grayLevels);
  1123.     void AppendToFile(char *filename,char *string);
  1124.     
  1125.     /* PlotXY.c */
  1126.     
  1127.     typedef struct{
  1128.         Boolean continuing;    /* zero to start a new curve */
  1129.         long color;            /* e.g. blackColor, blueColor */
  1130.         short lineWidth;    /* in pixels, zero for none */
  1131.         short symbolWidth;    /* in pixels, zero for none */
  1132.         short dashOffset;    /* in pixels */
  1133.         short dash[5];        /* in pixels. The array is terminated by a zero element */
  1134.         short h,v;            /* reserved for internal use */
  1135.         Fixed pathLengthF;    /* reserved for internal use */
  1136.     } PlotXYStyle;
  1137.     void PlotXY(WindowPtr window,double x,double y,PlotXYStyle *style);
  1138. #endif
  1139.  
  1140. /* PrintfExit.c */
  1141.  
  1142. int PrintfExit(const char *format,...);
  1143.  
  1144. #if MAC_C
  1145.     /* PrintfGWorld.c */
  1146.  
  1147.     void PrintfGWorld(GWorldPtr our);
  1148.     void PrintStringAsBitmap(unsigned char *s);
  1149. #endif
  1150.  
  1151. /* PupilMTF.c */
  1152.  
  1153. double PupilMTF(double cPerDeg,double diameterMm,double wavelengthNm);
  1154.  
  1155. #if MAC_C
  1156.     /* QD32Exists.c */
  1157.     
  1158.     Boolean         QD8Exists(void);
  1159.     Boolean            QD32Exists(void);
  1160.     Boolean            NewPaletteManager(void);
  1161. #endif
  1162.  
  1163. /* randU.c */
  1164.  
  1165. unsigned short    randU(void);
  1166. unsigned long    randUL(void);
  1167. void            srandU(unsigned n);
  1168. void            RandFill(void *address,long bytes);
  1169.  
  1170. /* ReadMATLABFile.c */
  1171.  
  1172. int LoadNamedMatIntoDoubles(FILE *f,const char *name,long *rows,long *cols
  1173.     ,double **real,double **imag);
  1174. int LoadNamedMatIntoShorts(FILE *f,const char *name,long *rows,long *cols
  1175.     ,short **real,short **imag);
  1176. int LoadNextMatIntoDoubles(FILE *f,char *name,long *rows,long *cols
  1177.     ,double **real,double **imag);
  1178. int LoadNextMatIntoShorts(FILE *f,char *name,long *rows,long *cols
  1179.     ,short **real,short **imag);
  1180. int SaveMatDoubles(FILE *f,char *name,long rows,long cols,double *real,double *imag);
  1181. int SaveMatShorts(FILE *f,char *name,long rows,long cols,short *real,short *imag);
  1182.  
  1183. #if MAC_C
  1184.     /* RectToAddress.c */
  1185.     
  1186.     unsigned char *RectToAddress(PixMap *pixMapPtr,Rect *rectPtr,short *rowBytesPtr, 
  1187.         short *pixelSizePtr,short *bitsOffsetPtr);
  1188.     Ptr GetPixBaseAddr32(PixMap **pm);
  1189. #endif
  1190.     
  1191. /*    Require.c    */
  1192.  
  1193. void Require(long quickDrawVersion);
  1194. struct PrecompileSizeofInt{
  1195.     int i;
  1196. };
  1197. struct PrecompileSizeofDouble{
  1198.     double d;
  1199. };
  1200.  
  1201. #if MAC_C
  1202.     /* RestoreCluts.c */
  1203.     
  1204.     void RestoreCluts(void);
  1205.     
  1206.     /*    SetEntriesQuickly.c */
  1207.     
  1208.     OSErr SetEntriesQuickly(GDHandle device,short start,short count,ColorSpec *table);
  1209.     short macltset(GDHandle device,register short start
  1210.         ,unsigned short *red,unsigned short *green,unsigned short *blue,short count1);
  1211.     short GetCardType(GDHandle device);
  1212.     char *GetCardBase(GDHandle device);
  1213.     OSErr WaitForNextBlanking(GDHandle device);
  1214.     
  1215.     /* SetFileInfo.c */
  1216.     
  1217.     void    SetFileInfo(char *fileName,OSType fileType,OSType fileCreator);
  1218.     
  1219.     /* SetGestaltValue1.c */
  1220.  
  1221.     OSErr SetGestaltValue1(OSType selector,long response);
  1222.  
  1223.     /* SetMouse.c */
  1224.     
  1225.     void    SetMouse(Point where);
  1226.     
  1227.     /* SetOnePixel.c */
  1228.     
  1229.     void SetPixmapPixel(PixMap *pmHandle,int x,int y,unsigned long value);
  1230.     unsigned long GetPixmapPixel(PixMap *pmHandle,int x,int y);
  1231.     unsigned char *GetPixmapPixelAddress(PixMap *pmHandle,int x,int y);
  1232.     void SetDevicePixel(GDHandle device,int x,int y,unsigned long value);
  1233.     unsigned long GetDevicePixel(GDHandle device,int x,int y);
  1234.     void SetOnePixel(int x,int y,unsigned long value);
  1235.     unsigned long GetOnePixel(int x,int y);
  1236.     #define SetIPixel SetDevicePixel    /*  So that old programs won't break. */
  1237.     #define GetIPixel GetDevicePixel    /*  So that old programs won't break. */
  1238.     
  1239.     /* SetPixelsQuickly.c */
  1240.     
  1241.     int SetPixelsQuickly(int x,int y,unsigned long value[],short n);
  1242.     int GetPixelsQuickly(int x,int y,unsigned long value[],short n);
  1243.     int SetWindowPixelsQuickly(WindowPtr window,int x,int y,unsigned long value[],short n);
  1244.     int GetWindowPixelsQuickly(WindowPtr window,int x,int y,unsigned long value[],short n);
  1245.     int SetDevicePixelsQuickly(GDHandle device,int x,int y,unsigned long value[],short n);
  1246.     int GetDevicePixelsQuickly(GDHandle device,int x,int y,unsigned long value[],short n);
  1247.     int SetPixmapPixelsQuickly(PixMapPtr pmPtr,int x,int y,unsigned long value[],short n);
  1248.     int GetPixmapPixelsQuickly(PixMapPtr pmPtr,int x,int y,unsigned long value[],short n);
  1249.     
  1250.     /* SetPriority.c */
  1251.     
  1252.     void SwapPriority(char *priority);
  1253.     void SetPriority(int i);
  1254.     int GetPriority(void);
  1255. #endif
  1256.  
  1257. /* Shuffle.c */
  1258.  
  1259. void Shuffle(void *array,long elements,size_t elementSize);
  1260.  
  1261. #if MAC_C
  1262.     /* SndPlay1.c */
  1263.     
  1264.     OSErr SndPlay1(Handle snd);
  1265.     void SndStop1(void);
  1266.     short SndDone1(void);
  1267.  
  1268.     /* StringToDateAndSecs.c */
  1269.     
  1270.     double StringToDateAndSecs(char *string,DateTimeRec *date);
  1271.  
  1272.     /* StringBounds.c */
  1273.     
  1274.     void CharBounds(char a,Rect *bounds,long *count);
  1275.     void StrBounds(char *s,Rect *bounds,long *count);
  1276.     double StrOutlineLength(char *s);
  1277.     void StringBounds(const unsigned char *s,Rect *bounds,long *count);
  1278.     double StringOutlineLength(const unsigned char *s);
  1279.  
  1280.     /* Timer.c */
  1281.     
  1282.     struct Timer{
  1283.         TMTask time;
  1284.         long ourA5;
  1285.         long interval,elapsed,elapsedIntervals;
  1286.         long timeToStartTimer;            /*  minimum time in µs */
  1287.         long stopDelay;                    /*  µs from call to stop, re from call to start */
  1288.         long timeManagerVersion;
  1289.         struct Timer *next,*previous;    /*  doubly linked list of Timers */
  1290.     };
  1291.     typedef struct Timer Timer;
  1292.     
  1293.     Timer *NewTimer(void);
  1294.     void DisposeTimer(Timer *t);
  1295.     void StartTimer(Timer *t);
  1296.     long StopTimer(Timer *t);                    /*  µs */
  1297.     double StopTimerSecs(Timer *t);                /*  s */
  1298.     long PeekTimer(Timer *t);                    /*  µs */
  1299.     double PeekTimerSecs(Timer *t);                /*  s */
  1300.     
  1301.     /* TitleBarHeight.c */
  1302.     
  1303.     int TitleBarHeight(WindowPtr window);
  1304.     
  1305.     /* TrapAvailable.c */
  1306.     
  1307.     Boolean    TrapAvailable(short theTrap);
  1308. #endif
  1309.  
  1310. /* Uniform.c */
  1311.  
  1312. double UniformSample(void);
  1313.  
  1314. #if MAC_C
  1315.     /* VBLInstall.c */
  1316.     
  1317.     struct VBLTaskAndA5 {
  1318.         volatile VBLTask vbl;
  1319.         long ourA5;
  1320.         #if USESROUTINEDESCRIPTORS || GENERATINGCFM
  1321.             UniversalProcPtr subroutine;
  1322.         #else
  1323.             void (*subroutine)(struct VBLTaskAndA5 *vblData);
  1324.         #endif
  1325.         GDHandle device;
  1326.         long slot;
  1327.         volatile long newFrame;        /* Boolean */
  1328.         volatile long frame;        /* count up from zero */
  1329.         volatile long framesLeft;    /* count down to zero */
  1330.         long framesDesired;
  1331.         Timer *frameTimer;            /* time ms since last VBL interrupt, see Timer.c */
  1332.         void *ptr;                    /* use this for whatever you want */
  1333.     };
  1334.     typedef struct VBLTaskAndA5 VBLTaskAndA5;    
  1335.     OSErr VBLInstall(VBLTaskAndA5 *vblData,GDHandle device,long frames);
  1336.     OSErr VBLRemove(VBLTaskAndA5 *vblData);
  1337.     void SimpleVBLSubroutine(VBLTaskAndA5 *vblData);
  1338.     
  1339.     /* VideoTFB.c */
  1340.     
  1341.     Boolean TFBInSlot(int slot);
  1342.     void    SetUpTFB(int slot);
  1343.     void    RampClutTFB(int slot);
  1344.     void    GrayClutTFB(int slot);
  1345.     void    LoadClutTFB(int slot,unsigned char rgb[256][3]);
  1346.     void    NewBlankingTFB(int slot);
  1347.     void    NewFieldTFB(int slot);
  1348.     int        BlankingTFB(int slot);
  1349.     void    SetDepthTFB(int slot,short int bits);
  1350.     void    SynchSetDepthTFB(int masterSlot,int slot,short int bits);
  1351.     void    SynchToMainDeviceTFB(GDHandle device);
  1352.     void    HaltTFB(int slot);
  1353.     void    RestartTFB(int slot,short int bits);
  1354.     void    HaltDeviceTFB(GDHandle device);
  1355.     void    RestartDeviceTFB(GDHandle device);
  1356.     void    ScrollTFB(int slot,short int bits,long x,long y);
  1357.     void    PanTFB(int slot,long int x);
  1358. #endif
  1359.  
  1360. /* VLambda.c */
  1361.  
  1362. double VLambda(double nm);
  1363. double VLambdaPrime(double nm);
  1364.  
  1365. #if MAC_C
  1366.     /* Zoom.c */
  1367.     
  1368.     void Zoom(WindowPtr theWindow,int zoomDir,EventRecord *event);
  1369. #endif
  1370.  
  1371. #endif /* _VIDEOTOOLBOX_ */
  1372.